package gamePieces;



import gameComponents.Player;

import java.awt.Point;
import java.util.ArrayList;

/**
 * Abstract class of a chess piece object. 
 * Each chess piece has an x and y coordinate to determine its position on the board, 
 * as well as a set of possible coordinates that they can move to on the board. 
 * Instances of class Piece cannot be created.
 * @author Jordan Beland
 */
public abstract class Piece {

	// x coordinate of chess piece
	protected int x;
	// y coordinate of chess piece
	protected int y;
	// Array made up of points determining the possible moves on the board each chess
	// piece has
	protected ArrayList<Point> moves;
	protected Player player;
	
	
	/**
	 * Constructor for a Piece object: the x and y coordinates and the creation of its
	 * list of possible moves.
	 * @author Jordan Beland
	 */
	public Piece(int x, int y, Player player) {
		this.x = x;
		this.y = y;
		this.moves = possibleMoves();
		this.player = player;
	}

	/**
	 * Default getter for x coordinate of Piece instance
	 * @author Jordan Beland
	 * @return x coordinate of piece
	 */
	public int getX() {
		return x;
	}

	/**
	 * Default getter for y coordinate of Piece instance
	 * @author Jordan Beland
	 * @return y coordinate of piece
	 */
	public int getY() {
		return y;
	}
	
	/**
	 * Default setter for the x coordinate of Piece instance
	 * @author Selman Selman
	 * @param x coordinate of piece
	 */
	public void setX(int x) {
		this.x = x;
	}
	/**
	 * modified to return player instead
	 * @return Player owner
	 * @modified by Selman Selman
	 */
	public Player getOwnership() {
		return player;
	}

	/**
	 * Default setter for the y coordinate of Piece instance
	 * @author Selman Selman
	 * @param y coordinate of piece
	 */
	public void setY(int y) {
		this.y = y;
	}
	/**
	 * Returns the list of possible moves of the Piece.
	 * @author Jordan Beland
	 * @return list of possibleMoves
	 */
	public ArrayList<Point> getMoves(){
		return this.moves;
	}
		
	/**
	 * Calculates a list of possible moves for a Piece at
	 * the current position.
	 * Method is overwritten by each subclass of Piece. 
	 * @author Jordan Beland
	 * @return ArrayList of all the points the piece could IDEALLY move to.
	 */
	public abstract ArrayList<Point> possibleMoves();
	/**
	 * Checks if the Piece's move is legal based on its list of possible moves.
	 * @param x - the x coordinate the Piece will move to
	 * @param y - the y coordinate the Piece will move to
	 * @return - True if the move is legal, false if not.
	 * @author - Vivian Andreeva, Selman Selman
	 */
	public abstract boolean checkIfLegal(int x, int y);
	
 	/**
	 * Changes the x and y coordinates of piece
	 * @author Jordan Beland
	 * @param x coordinate of piece
	 * @param y coordinate of piece
	 */
	public void move(int x, int y){
		if(checkIfLegal(x,y)){
		this.x = x;
		this.y = y;
		}
	}
	
	/**
	 * toString method.
	 */
	public abstract String toString();
	
}